package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.entity.Shipping;
import com.situ.mall.entity.Result;
import com.situ.mall.mapper.ShippingMapper;
import com.situ.mall.service.IShippingService;

@Service
public class ShippingServiceImpl implements IShippingService{
	@Autowired
	private ShippingMapper shippingMapper;

// 0.测试
	@Override
	public List<Shipping> selectAll() {
		return shippingMapper.selectAll();
	}
//后台
// 1.页面展示 
	@Override
	public Result selectByPage(Integer page, Integer limit) {
		//总个数
		int count = shippingMapper.getTotalCount();
		
		//每页信息
		int offset = (page-1)*limit;
		List<Shipping> list = shippingMapper.selectByPage(offset,limit);
		
		return Result.success("", list, count);
	}

//2.批量删除
	@Override
	public boolean deleteAll(Integer[] ids) {
		int count = 0;				//1.记数
		for (Integer id : ids) {	//2.循环删除，根据id.length 有几个id删除几次
			int c = shippingMapper.deleteByPrimaryKey(id); //3. 每次 根据id删除
			count+=c;	//4.删除一次，删除记录+1
		}
		return count== ids.length ? true:false; // 5.删除记录次数 == id[]个数相等 (确保都删了)；删除成功，否则失败05
	}

//3.删除
	@Override
	public boolean deleteById(Integer id) {
		int count= shippingMapper.deleteByPrimaryKey(id);
		return count==1 ? true:false;
	}

//前台
	//1.cart_list结算 --》 order_confirm 获取 用户的所有地址 by userId
	@Override
	public List<Shipping> selectOrderConfirmShippingInfoByUserId(Integer userId) {
		List<Shipping> shippingList = shippingMapper.selectOrderConfirmShippingInfoByUserId(userId);
		return shippingList;
	}

	

}
